# Author    :Dun_Hz
# Time      :2024/3/18 9:43
# 列表之列表

# 构建二叉树
def make_binary_tree(root):
    return [root, [], []]

# 插入左子树
# 首先获取左子树对应的列表，然后加入新的左子树，将旧的左子树作为新节点的左子树
def insert_left(root, new_child):
    old_child = root.pop(1)
    if len(old_child)>1:
        root.insert(1, [new_child,old_child,[]])
    else:
        root.insert(1, [new_child, [], []])
    return root

# 插入右子树，旧的右子树放在新节点的右子树
def insert_right(root,new_child):
    old_child = root.pop(2)
    if len(old_child)>1:
        root.insert(2,[new_child, [], old_child])
    else:
        root.insert(2,[new_child,[],[]])
    return root

# 树的访问
def get_root_val(root):
    return root[0]
def set_root_val(root,new_value):
    root[0]=new_value
def get_left_child(root):
    return root[1]
def get_right_child(root):
    return root[2]

if __name__ == '__main__':
    a_tree = make_binary_tree(3)
    print(a_tree)
    insert_left(a_tree, 4)
    print(a_tree)
    insert_left(a_tree, 5)
    print(a_tree)
